import * as types from './mutation-types'
import Vue from 'vue'

export default {
  [types.SET_NOTICE_UNDEALNUM] (state, data) {
    // 更新右上角小铃铛的未读数
    if (data.undealNum <= 0) {
      state.globalLet.undealNum = 0
    } else {
      state.globalLet.undealNum = data.undealNum
    }
  },
  [types.PHONE_DATA] (state, data) {
    // 电话条基础数据 详细可见 ctiInit 方法
    let phoneData = data.phoneData
    if (phoneData) {
      for (let key in phoneData) {
        if (phoneData[key]) {
          if (key === 'busyType') {
            state.globalLet.busyType = phoneData[key]
          } else if (key === 'extenType') {
            state.globalLet._cti_extenType = phoneData[key]
          }
          Vue.set(state.globalLet.phone_data, key, phoneData[key])
        }
      }
    } else {
      state.globalLet.phone_data = {}
    }
  },
  [types.CTI_ISRELOGIN] (state, data) {
    // 电话条是否断网重连，避免重连action还没返回又再次重连
    state.globalLet._cti_isRelogin = data
  },
  [types.CTI_ISSETTINGBUSY] (state, data) {
    // 电话条是否切换状态中，避免action还没返回又再次发送action
    state.globalLet._cti_isSettingbusy = data
  },
  [types.PHONE_TRANSFERREASON] (state, data) {
    // 电话条转接原因
    state.globalLet.transferData = data
  },
  [types.CTI_ALLAGENTSTATUS] (state, data) {
    // 获取所有坐席的空闲状态
    state.globalLet._cti_allAgentStatus = data
  },
  [types.CTI_URL] (state, data) {
    // 当前账号所在的pbx配置里的url，使用位置：电话条jsonp请求&&心跳图请求（计费位置：资源 =》 呼叫中心 =》 pbx管理 =》 pbx详情中的路由ip)
    state.globalLet._cti_url = data
  },
  [types.CTI_STATEBEFOREHOLD] (state, data) {
    // 记住保持通话前的状态，恢复通话时清空
    state.globalLet._cti_stateBeforeHold = data
  },
  [types.CTI_ISINVESTIGATTING] (state, data) {
    // 是否转满意度中，避免action还没返回又再次发送action
    state.globalLet._cti_isInvestigatting = data
  },
  [types.PHONE_PBXS] (state, {data, type}) {
    // 当前账户所在的pbx的配置信息
    for (let key in data) {
      if (data[key]) {
        state.globalLet.phone_pbxs[type] = data[key]
      }
    }
  },
  [types.CTI_CURRENTSTATE] (state, data) {
    // 当前电话条状态的下标 和 _cti_stateDescription 结合使用 eg: unregister，dialing
    let preState = state.globalLet._cti_currentState
    state.globalLet._cti_preState = preState
    state.globalLet._cti_currentState = data
  },
  [types.PHONECALLOBJECT] (state, data) {
    // 当前通话中的数据，暂时只用上了callId，其他数据暂时没有使用的地方
    let phoneCallObject = data.phoneCallObject
    if (phoneCallObject) {
      for (let key in phoneCallObject) {
        if (phoneCallObject[key]) {
          state.globalLet._phone_callObject[key] = phoneCallObject[key]
        }
      }
    } else {
      state.globalLet._phone_callObject = {}
    }
  },
  [types.CTI_UI_LAST_STATE] (state, data) {
    // 存储电话条的状态（当前的状态eg:  talking、innerBelling等）
    state.globalLet._cti_ui_last_state = data
  },
  [types.PHONE_SERVICENOS] (state, data) {
    // 服务号发生变化时，重新计算并渲染监控的数据
    state.serviceNoChange.random = Math.random()
  },
  [types.PHONE_QUEUES] (state, data) {
    // 技能组发生变化时，重新计算并渲染监控的数据
    state.phoneQueuesChange.random = Math.random()
  },
  [types.PHONE_ACCOUNTCALLS] (state, data) {
    // 当前账户所在的pbx的通话数据
    let pbx = data.pbx
    let account = data.account
    if (state.globalLet.phone_accountCalls[pbx]) {
      for (let key in account) {
        Vue.set(state.globalLet.phone_accountCalls[pbx], key, account[key])
      }
    } else {
      Vue.set(state.globalLet.phone_accountCalls, pbx, data.account)
    }
  },
  [types.CTI_UI_COUNTTIMER] (state, data) {
    // 电话条上的计时是否要重新计时或者是变成倒计时的标志
    state.globalLet._cti_ui_countTimer = data
  },
  [types.CTI_UI_CALCULAGRAPH] (state, data) {
    // 电话条计时，临时存储的定时器值，若是新增一个定时器的时候清除之前的
    state.globalLet._cti_ui_calculagraph = data
  },
  [types.MTIME] (state, data) {
    // 电话条上展示的时间 00:00:00
    state.globalLet.mtime = data
  },
  [types.TIMING_OR_COUNT_DOWN] (state, data) {
    // 软电话条正计时还是倒计时
    state.globalLet.timingOrCountDown = data
  },
  [types.BUSYTYPE] (state, data) {
    // 当前展示的电话条繁忙状态（下拉中列表中不会有当前已选的项）
    state.globalLet.busyType = data
  },
  [types.CTI_SHOWNUMBER] (state, data) {
    // 软电话条是否显示号码
    state.globalLet._cti_showNumber = data
    if (!data) {
      state.globalLet.calleeArea = ''
    }
  },
  [types.CTI_EXTENSTATE] (state, data) {
    // 电话条状态为consultTalking、talking、threeWayTalking时控制icon的展示
    state.globalLet._cti_extenState = data
  },
  [types.WAITSATE] (state, data) {
    // 转接或者是咨询后的等待ing
    for (let key in data) {
      Vue.set(state.globalLet.waitSate, key, data[key])
    }
  },
  [types.SHOWTRANSFERDIALOG] (state, data) {
    // 是否展示转接弹窗
    state.globalLet.showTransferDialog = data
  },
  [types.CTI_UI_NOTIFYDIALOGINTERVAL] (state, data) {
    // 存储转接或咨询ing计时的定时器
    state.globalLet._cti_ui_notifyDialogInterval = data
  },
  [types.CTI_UI_DIALOGBOXREMAIN] (state, data) {
    // 转接或咨询ing时间计时，若是超过40s自动关闭弹窗
    state.globalLet._cti_ui_dialogBoxRemain = data
  },
  [types.SHOWTRANSFERCANCELDIALOG] (state, data) {
   // 转接或咨询的等待ing弹窗
    state.globalLet.showTransferCancelDialog = data
  },
  [types.CALLEEAREA] (state, data) {
    // 电话条号码归属地
    state.globalLet.calleeArea = data
  },
  [types.CURRENTCALLSHEETID] (state, data) {
    // 当前通话中的通话id
    state.globalLet.currentCallSheetId = data
  },
  [types.CALL_SCREEN] (state, data) {
  // 外呼弹屏对接url
    state.globalLet.callScreen = data
  },
  [types.CALL_CUSTOMER_DETAIL] (state, data) {
    // 外呼弹屏的当前客户对象，未知客户or多个客户or一个客户
    state.globalLet.callCustomerDetail = data
  },
  [types.SCREEN_FLAG] (state, data) {
    // 当前外呼弹屏的标志，用于是否出现外呼弹屏
    state.globalLet.callFlag = data
  },
  [types.CURRENT_CUST_INFO] (state, data) {
    // 当前通话的客户信息
    state.currentCustInfo = data
  },
  [types.SCREEN_CALL_SHEET_ID] (state, data) {
    // 当前外呼弹屏中的通话id,用于新增客户or更新客户or合并客户
    state.globalLet.screenCallSheetId = data
  },
  [types.OUTBOUND_SCREEN_CALL_SHEET_ID] (state, data) {
    // 当前外呼的通话id,挂断电话会清空
    state.globalLet.outboundScreenCallSheetId = data
  },
  [types.CALLINGNUM] (state, data) {
    // 电话条外呼正在通话中的号码
    state.globalLet.callingNum = data
  },
  [types.CALLSCREEN_CALLINGNUM] (state, data) {
    // 外呼弹屏中用的正在通话中的号码，和电话条中显示callingNum断开关联
    state.globalLet.callScreenCallingNum = data
  },
  [types.CALL_BY_SIP_OR_GETWAY] (state, data) {
    // sip话机或者是软电话上外呼的号码，重新赋值外呼弹屏中的号码
    state.globalLet.callBySipOrGetway = data
  },
  [types.BUSYTYPENAME] (state, data) {
    // 所有电话条状态名字配置 eg: 小休
    state.globalLet.busyTypeName = data
  },
  [types.SHOWCONSULTDIALOG] (state, data) {
    // 是否展示咨询弹窗
    state.globalLet.showConsultDialog = data
  },
  [types.LIMITS] (state, data) {
    // 监控呼入并发上限数
    state.globalLet.limits = data
  },
  [types.QUEUE_NUMBER] (state, data) {
    // 所在技能组通话排队总数
    state.globalLet.queueNumber = data
  },
  [types.CURRENT_CALL_UP_HANDUP] (state, data) {
    // 来电之后接起或者是挂断，用于来电添加备注（来电已接听的有备注按钮，调用通话中打备注的接口，挂断之后走普通打备注的接口）
    state.globalLet.currentCallUpHandup = data
  },
  [types.PHONE_QUEUES_CHANGE] (state, userId) {
    // 技能组发生变化时，重新计算并渲染监控的数据
    state.phoneQueuesChange.random = Math.random()
  },
  [types.CALL_IN_FLAG] (state, data) {
    // 来电的标识，用于区别电话条的状态切换
    state.globalLet.callInFlag = data
  },
  [types.IS_SHOW_CANCLE_COUNSULT_BTN] (state, data) {
    // 是否显示咨询的取消按钮，默认不展示
    state.globalLet.isShowCancleCounsultBtn = data
  },
  [types.LOCKD_STATE_LOGOFF] (state, data) {
    // 设置退出锁 防止退出请求延迟 发起重登请求
    state.globalLet.lockd_state.logoff = data
  },
  [types.ASS_NEW_FEATURES] (state, data) {
    state.globalLet.ass_new_features = data
  },
  [types.ASS_CURRENT_NEW_FEATURES] (state, data) {
    state.globalLet.ass_current_new_features = data
  },
  [types.VAL_OF_IVR_MENU_DIALOG] (state, data) {
    state.globalLet.valOfIvrMenuDialog = data
  },
  [types.WORK_NUMBER_BINDING_STATUS] (state, data) {
    // 工号绑定状态
    state.globalLet.work_number_binding_status = data
  },
  [types.RISK_DIALOG] (state, data) {
    // 风控弹窗
    state.globalLet.riskDialog = data
  },
  [types.RISK_DATA] (state, data) {
    // 风控数据
    state.globalLet.riskData = data
  },
  [types.IS_LABEL_SHOW] (state, data) {
    // 通话标签展示标识
    state.globalLet.isLabelShow = data
  },
  [types.IS_CALLING] (state, data) {
    // 通话中的标识
    state.globalLet.isCalling = data
  },
  [types.AUTO_HANGUP_LIST] (state, data) {
    // 转三方之后，发起方可以选择挂机客户端还是被咨询方
    state.globalLet.autoHangupList = data
  }
}
